/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package kimo.bl;

import java.util.Date;
import static kimo.bl.zkUtils.setCheckValue;
import static kimo.bl.zkUtils.setTextboxValue;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;

/**
 *
 * @author a381u296
 */
public class ProdConfirmation extends KimoUI {

    @Wire
    Checkbox producer_confirm_1;
    @Wire
    Textbox producer_comment_1;

    @Wire
    Checkbox producer_confirm_2;
    @Wire
    Textbox producer_comment_2;

    @Wire
    Checkbox producer_confirm_3;
    @Wire
    Textbox producer_comment_3;

    @Wire
    Checkbox producer_confirm_4;
    @Wire
    Textbox producer_comment_4;

    @Wire
    Checkbox producer_confirm_5;
    @Wire
    Textbox producer_comment_5;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp); //To change body of generated methods, choose Tools | Templates.

    }

    @Override
    void getFromUI() {
        getProducer().setProducerConfirm1(producer_confirm_1.isChecked());
        getProducer().setProducerComment1(producer_comment_1.getText());

        getProducer().setProducerConfirm2(producer_confirm_2.isChecked());
        getProducer().setProducerComment2(producer_comment_2.getText());

        getProducer().setProducerConfirm3(producer_confirm_3.isChecked());
        getProducer().setProducerComment3(producer_comment_3.getText());

        getProducer().setProducerConfirm4(producer_confirm_4.isChecked());
        getProducer().setProducerComment4(producer_comment_4.getText());

        getProducer().setProducerConfirm5(producer_confirm_5.isChecked());
        getProducer().setProducerComment5(producer_comment_5.getText());

    }

    @Override
    void updateUI() {

        setCheckValue(producer_confirm_1, getProducer().getProducerConfirm1());
        setTextboxValue(producer_comment_1, getProducer().getProducerComment1());

        setCheckValue(producer_confirm_2, getProducer().getProducerConfirm2());
        setTextboxValue(producer_comment_2, getProducer().getProducerComment2());

        setCheckValue(producer_confirm_3, getProducer().getProducerConfirm3());
        setTextboxValue(producer_comment_3, getProducer().getProducerComment3());

        setCheckValue(producer_confirm_4, getProducer().getProducerConfirm4());
        setTextboxValue(producer_comment_4, getProducer().getProducerComment4());

        setCheckValue(producer_confirm_5, getProducer().getProducerConfirm5());
        setTextboxValue(producer_comment_5, getProducer().getProducerComment5());

    }

    @Override
    void populateListboxs() {

    }

    @Override
    void clearUI() {

    }

    @Listen("onClick = #confirmSaveBtn")
    public void onConfirmSaveBtnClick() throws Exception {
        saveProducer();
        Messagebox.show("Αποθηκευτηκε !");
    }

    @Listen("onClick = #confirmConfirmationBtn")
    public void onConfirmConfirmation() throws Exception {
        saveProducer();

        if (checkconfirm()) {
            getProducer().setProducerConfirmDate(new Date());
            getProducer().setProducerConfirmed(true);
            Messagebox.show("H αίτηση του παραγωγού εγκρίθηκε !");
             saveProducer();
            Executions.sendRedirect("");
        } else {
            Messagebox.show("Πρεπει να γινει επιβεβαίωση ολων των δικαιολογητικών");
        }

    }

    private Boolean checkconfirm() {

        return (getProducer().getProducerConfirm1())
                && (getProducer().getProducerConfirm2())
                && (getProducer().getProducerConfirm3())
                && (getProducer().getProducerConfirm4())
                && (getProducer().getProducerConfirm5());

    }

}
